package com.example.spring.boot.gson.controller;

import com.example.spring.boot.gson.pojo.vo.MessageInfoVO;
import com.example.spring.boot.gson.pojo.vo.MessageListVO;
import com.example.spring.boot.gson.utils.GsonUtil;
import com.google.gson.Gson;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * TestController
 * </p>
 *
 * @author weixin
 * @date 2023/3/27 22:59
 */
@RestController
public class GsonController {

    public static void main(String[] args) {



        MessageInfoVO messageInfoVO = new MessageInfoVO();
        messageInfoVO.setMessageId(1);
        messageInfoVO.setMessageType(0);
        messageInfoVO.setRead(0);
        messageInfoVO.setShow(1);
        messageInfoVO.setTelephoneName("15321375192");
        messageInfoVO.setTelephoneNum("15321375192");
        messageInfoVO.setTelephoneStatus(3);
        messageInfoVO.setTextType(0);
        messageInfoVO.setCreateTime("2023-03-27 10:40:39");

        List<MessageInfoVO> list = new ArrayList<>();
        list.add(messageInfoVO);

        MessageListVO messageListVO = new MessageListVO();

        Gson gson = new Gson();
        String listJson = gson.toJson(list);
        //String listJsonStr = GsonUtil.formatJson(listJson);
        messageListVO.setMessageJson(listJson);

        String json = gson.toJson(messageListVO);
        String jsonStr = GsonUtil.formatJson(json);

        System.out.println(jsonStr);

        String message = "{\"messageList\":[\"{\\\"createTime\\\":\\\"2023-03-27 10:40:39\\\",\\\"messageId\\\":1,\\\"messageType\\\":0,\\\"read\\\":0,\\\"show\\\":1,\\\"telephoneName\\\":\\\"15321375192\\\",\\\"telephoneNum\\\":\\\"15321375192\\\",\\\"telephoneStatus\\\":3,\\\"textType\\\":0}\"]}";


    }

}
